What to set the scalar type to contain a byte []. Entity in MVC2

Posted by Brad8118 on Stack Overflow See other posts from Stack Overflow or by Brad8118
Published on 2010-12-31T17:47:56Z Indexed on 2010/12/31 17:54 UTC
Read the original article Hit count: 153

I'm trying out the EF 4.0 and using the Model first approach. I'd like to store images into the database and I'm not sure of the best type for the scalar in the entity.
I currently have it(the image scalar type) setup as a binary. From what I have been reading the best way to store the image in the db is a byte[]. So I'm assuming that binary is the way to go. If there is a better way I'd switch.

In my controller I have:

 //file from client to store in the db
 HttpPostedFileBase file = Request.Files[inputTagName];
 if (file.ContentLength > 0)
 {
   keyToAdd.Image = new byte[file.ContentLength];
   file.InputStream.Write(keyToAdd.Image, 0, file.ContentLength);
 }

This builds fine but when I run it I get an exception writing the stream to keyToAdd.Image. The exception is something like: Method does not exist.

Any ideas? Note that when using a EF 4.0 model first approach I only have int16, int32, double, string, decimal, binary, byte, DateTime, Double, Single, and SByte as available types. Thanks

© Stack Overflow or respective owner

Related posts about database

Related posts about image